package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.Dependencies.Realization;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.uml.commands.ConnectionModelCreateCommand;
import edu.pku.sei.modeler.uml.commands.UMLConnectionCreateCommand;

public class UMLRealizationCreateCommand extends ConnectionModelCreateCommand {


	public UMLRealizationCreateCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel) {
		super(connectionModel, sourceModel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void undo() {
		Realization realization = (Realization)connectionModel;
		realization.getSupplierDependency().remove(realization);
		realization.getClientDependency().remove(sourceModel);
		Classifier sourceModelElement = (Classifier) sourceModel;
		sourceModelElement.getSupplierDependency().remove(realization);

	}

	@Override
	public void execute() {
		Realization realization = (Realization) connectionModel;
		//realization.setModel(this.source.getModelElement().getModel());
		realization.getSupplierDependency().add(realization);
		realization.getClientDependency().add(sourceModel);
		Classifier sourceModelElement = (Classifier) sourceModel;
		sourceModelElement.getSupplierDependency().add(realization);


	}


	@Override
	public boolean canExecute() {
		return true;
	}
	
}
